<?php

if(isset($_GET['searchApho'])){
    header("location:../search?queryApho=".$_GET['qaph']);
}

$link = mysql_connect("mysql-88.ukraine.com.ua", "barthez_ai", "x9gedv4w");
if (!$link) {
    die('Could not connect: ' . mysql_error());
}
if (isset($_GET['start']) && isset($_GET['count'])) {
    $start = $_GET['start'];
    $count = $_GET['count'];
}
mysql_set_charset('utf8', $link);
mysql_select_db('barthez_ai');

$sql = "SELECT count(*) FROM `byone` LIMIT 1";
$result = mysql_query($sql);

while ($row = mysql_fetch_array($result)) {
    $allcount = $row[0];
}

$byPage = 10;

if (!isset($start))
    $start = rand(1, $allcount/$byPage-1);
if (!isset($count))
    $count = $byPage;


$sql = "SELECT * FROM `byone` LIMIT $start, $count";


$result = mysql_query($sql);

$allresults = array();
$counter = 1;

while ($row = mysql_fetch_assoc($result)) {
    $allresults[$counter] = $row;
    $counter++;
}


$sql2 = "SELECT * FROM `byone` GROUP BY theme ORDER BY RAND() LIMIT 10";
$result2 = mysql_query($sql2);

$allAuthors = array();
while ($row = mysql_fetch_assoc($result2)) {
    $allAuthors[] = $row['theme'];
}

$sql3 = "SELECT * FROM `byone` ORDER BY RAND() LIMIT 5";
$result3 = mysql_query($sql3);


$allRandApho = array();

while ($row = mysql_fetch_assoc($result3)) {
    $temp = array();
    $temp['text'] = $row['text'];
    $temp['theme'] = $row['theme'];
    
    $allRandApho[]=$temp;
}

?>


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> 
<html>
     <head>
        <script type="text/javascript" src="jquery.js"></script>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF8" >
        <title>Афоризмы, крылатые выражения, цитаты, поговорки, высказывания. Страница <? print floor($start / $count); ?> - deeflow.com/vka/vk.php</title>
        <meta name="description" content="Кропотливо собранные более 25 тысяч афоризмов всех времен и народов.- deeflow.com/vka/vk.php">
        <meta name=Robots content="index,follow">
        <link rel="stylesheet" href="http://deeflow.com/css/cssfw/minniFw.css" type="text/css">
        
        <base href="http://deeflow.com/"/>  
        
        <style>
    h2{
        font-size: 10px;

        margin: 2px;
        padding: 2px;

    }
    .part{

        width: 480px;
        vertical-align: top;
        font-size: 11px;
        font-family: verdana, arial, sans-serif;
        background-color: #627AAD;
        border: 1px solid lightsteelblue;
        
        margin: 2px;
        padding: 2px;
        display: inline-block;
    }
    
    .partR{
        border: 1px solid lightsteelblue;
        
        margin: 2px;
        padding: 4px;
        width: 250px;
        background-color: #627AAD;
        display: inline-block;
        
    }
    .partRight{
        
        width: 300px;
        vertical-align: top;
        font-size: 11px;
        font-family: Verdana;
        display: inline-block;
        
    }

    .part .head{
        font-size: 11px;
        color: black;
        background-color: #627AAD;

        height: 24px;  
        -moz-border-radius:5px;
        -webkit-border-radius:5px;
        margin: 0px auto;
        text-align: center;

    }

    .part .body{
        font-size: 11px;

        color: white;
        padding: 3px;
        padding-left: 10px;

    }
    .part .body p{
        margin: 4px;
    }
    .part span{
        color: white;
    }
    .part .footer{
        text-align: center;
    }
    .part .body a, a:visited{
        color: white;
    }

    .part .body a:hover{
        color: white;
    }
    .part .linkFoot{
        width: 200px;
        color: white;
        background-color: #627AAD;

        -moz-border-radius:5px;
        -webkit-border-radius:5px;
    }


    .part .onelink{
        margin: 2px 5px;
        width: 38px;
        display: inline-block;
        text-align: center;
    }
    
    .selected{
        -moz-border-radius:2px;
        -webkit-border-radius:2px;
        background-color: #627AAD;
        color: black;
    }
     a,a:visited,a:hover{
        color: white; 
    }
    .noselected a,.noselected a:visited,.noselected a:hover{
        color: white;
    }
    
    .headTitle{
        color: white; 
        font-size: 11px; 
        margin: 5px;
        font-weight: bold;
    }
    
    .likes{
        min-height: 60px;
    }
    .hl{
        background-color: #3B5998;
    }
    
</style>
    



    <div id="fb-root"></div>
    <script src="http://connect.facebook.net/en_US/all.js#xfbml=1"></script>
    <script>
        FB.init({
            appId  : '178102922208034',
            status : true, // check login status
            cookie : true, // enable cookies to allow the server to access the session
            xfbml  : true  // parse XFBML
        });
    </script>
  </head>
  
   <div class="w-500 margin-auto">
    <div class="part disp-in-bl"> 
        <div class="body" id="aphorismsList"> 
            <div class="disp-in-bl">
                <? if ($start - 1 > 0): ?>
                    <a href="./vka/vk.php?start=<? print $start - 1; ?>&count=<? print $count ?>">&larr;Пред</a>
                <? endif; ?>
            </div>
            <div class="disp-in-bl tal-right">
                <a href="./vka/vk.php?start=<? print rand(1, floor($allcount/$count)-1) ?>&count=<? print $count?>">случайно</a>
            </div>
            <div class="disp-in-bl tal-right">
                <? if (($start+1)< $allcount / $count): ?>
                    <a href="./vka/vk.php?start=<? print $start + 1; ?>&count=<? print $count?>">След&rarr;</a>
                <? endif; ?>
            </div>
            <div class="tal-right w200 disp-in-bl float-r"> 
                <span class="headTitle">Страница  <? print floor($start); ?> из <? print floor($allcount / $count) - 1; ?></span>
            </div> 
        </div>
        <hr />
        <div class="body" id="aphorismsList"> 

            <? $counter = $start * $count; ?>

            <? foreach ($allresults as $oneResult): ?>

                <span style="color: white; font-size:10px;"><? print $counter; ?></span>
                    
                    <a href="http://deeflow.com/vka/oneaphorism.php?id=<? print $oneResult['aphorismId']; ?>"><span><? print $oneResult['theme']; ?></span></a>
                    
                    <div class="pm-4 likes" id="apho-<? print $oneResult['aphorismId'];?>" supervalue="<? print $oneResult['aphorismId'];?>">
                        <div class="disp-in-bl w-350 valign-top">
                            <? print $oneResult['text']; ?>
                        </div>
                        
                        <div class="w-80 disp-in-bl hide" id="buttonapho-<?print $oneResult['aphorismId'];?>">
                            
                        </div>
                    </div>
                <? $counter++; ?>

            <? endforeach; ?>
        </div> 
    </div>
        
       
        


    <div class="partRight">
        

        <div class="partR disp-in-bl">

            <div class="linkFoot">
                <div class="tal-right">
                    
                         <span class="headTitle">deeflow | Поиск в афоризмах</span><br />
                </div>
                <hr />
                <div class="tal-center">
                    <form method="GET">
                       <input name="qaph" value="" style="width: 200px;"/>
                       <input name="searchApho" type="submit" value="Найти в афоризмах" style="width: 200px;"/>
                   </form>
                </div>

            </div>
        </div>

        <div class="partR disp-in-bl">

            <div class="linkFoot">
                <div class="tal-right">
                    <span class="headTitle">Случайные авторы</span><br />
                </div>
                <hr />
                <? foreach ($allAuthors as $oneResult): ?>
                        <a href="../search?queryApho=<?print $oneResult?>"><? print $oneResult?></a><br />
                <? endforeach;?>
            </div>
        </div>
        
        <div class="partR disp-in-bl">

            <div class="linkFoot">
                <div class="tal-right">
                    <span class="headTitle">Случайные выражения</span><br />
                </div>
                <hr />
                <? foreach ($allRandApho as $oneResult): ?>
                        <a href="../search?queryApho=<?print $oneResult['theme']?>">
                            <? print $oneResult['theme']?></a><span class="c-white">: <? print $oneResult['text']?></span>
                        
                        <br />
                        <br />
                <? endforeach;?>
            </div>
        </div>

    </div>
            </div>
</html>